using System.Collections;
using Slaks.Graphs;
using Slaks.Graphs.Algorithms;
using Slaks.Graphs.Algorithms.DistanceAlgorithm;

namespace Slaks.GraphExtensions.Algorithms
{
	public class SuperGraphDistances
	{
		#region size vertex edge count

		public static long GetSuperGraphSizeVertexEdgeCount(SuperGraph superGraph)
		{
			long distance = 0;
			ICollection graphs = superGraph.GetGraphs();
			foreach (Graph graph in graphs)
			{
				distance += graph.GetGraphSizeVertexEdgeCount;
			}
			return distance;
		}

		#endregion

		#region Dist MCS Vertex Edge Count

		public static double DistMCS4VertexEdgeCount(SuperGraph one, SuperGraph two)
		{
			ICollection graphsOne = one.GetGraphs();
			ICollection graphsTwo = two.GetGraphs();

			SuperGraph superGraph;
			ICollection collection;
			if (graphsOne.Count > graphsTwo.Count)
			{
				collection = graphsOne;
				superGraph = two;
			}
			else
			{
				collection = graphsTwo;
				superGraph = one;
			}

			Graph graphTwo;

			double distance = 0.0;
			foreach (Graph graph in collection)
			{
				graphTwo = superGraph.GetGraphBySectionType(graph.Category);
				if (graphTwo == null)
				{
					distance += 1;
					continue;
				}
                GraphDistanceBase dist = new Graphs.Algorithms.DistanceAlgorithm.DistMCS4VertexEdgeCount(graph, graphTwo);
                
				distance += dist.GetDistance ();
			}
			return distance;
		}

		#endregion

		#region Dist WGU Vertex Edge Count

		public static double DistWGU4VertexEdgeCount(SuperGraph one, SuperGraph two)
		{
			ICollection graphsOne = one.GetGraphs();
			Graph graphTwo;

			double distance = double.MaxValue;
			foreach (Graph graph in graphsOne)
			{
				graphTwo = two.GetGraphBySectionType(graph.Category);
				if (graphTwo == null) continue;
				if (distance == double.MaxValue) distance = 0.0;
                GraphDistanceBase dist = new DistWGU4VertexEdgeCount(graph, graphTwo);
				distance += dist.GetDistance();
			}
			return distance;
		}

		#endregion

//===========================================================================================

		#region size vertex edge count

		public static double GetSuperGraphSizeVertexFrequency(SuperGraph superGraph)
		{
			double distance = 0;
			ICollection graphs = superGraph.GetGraphs();
			foreach (Graph graph in graphs)
			{
				distance += graph.GetGraphSizeVertexEdgeFrequency;
			}
			return distance;
		}

		#endregion

		#region Dist MCS Vertex Edge Frequency

		public static double DistMCS4VertexEdgeFrequency(SuperGraph one, SuperGraph two)
		{
			ICollection graphsOne = one.GetGraphs();
			Graph graphTwo;

			double distance = double.MaxValue;
			foreach (Graph graph in graphsOne)
			{
				graphTwo = two.GetGraphBySectionType(graph.Category);
				if (graphTwo == null) continue;
				if (distance == double.MaxValue) distance = 0.0;
                GraphDistanceBase dist = new DistMCS4VertexEdgeFrequency(graph, graphTwo);
				distance += dist.GetDistance();
			}
			return distance;
		}

		#endregion

		#region Dist WGU Vertex Edge Frequency

		public static double DistWGU4VertexEdgeFrequency(SuperGraph one, SuperGraph two)
		{
			ICollection graphsOne = one.GetGraphs();
			Graph graphTwo;

			double distance = double.MaxValue;
			foreach (Graph graph in graphsOne)
			{
				graphTwo = two.GetGraphBySectionType(graph.Category);
				if (graphTwo == null) continue;
				if (distance == double.MaxValue) distance = 0.0;
                GraphDistanceBase dist = new DistWGU4VertexEdgeFrequency(graph, graphTwo);
				distance += dist.GetDistance();
			}
			return distance;
		}

		#endregion

//=============================================================================================

	}
}